package com.jboa.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jboa.dao.RoleFunctionDao;
import com.jboa.model.Function;
import com.jboa.model.Module;
import com.jboa.model.Role;
import com.jboa.model.RoleFunction;



public class RoleFunctionDaoImpl extends HibernateDaoSupport implements
		RoleFunctionDao {

	public void delete(RoleFunction entity) {
		super.getHibernateTemplate().delete(entity);

	}

	public List<RoleFunction> findBy2Properties(String propertyName1,
			String propertyName2, Object value1, Object value2) {
		String hql="from RoleFunction rf where rf."
			+propertyName1+"=? and rf."+propertyName2+"=?";
		return super.getHibernateTemplate().
				find(hql,new Object[]{value1,value2});
		
	}

	public List<RoleFunction> findByProperty(String propertyName, Object value) {
		String hql="from RoleFunction rf where rf."+propertyName+"=?";
		return super.getHibernateTemplate().find(hql,value);
		
	}

	public List<Function> findFInRM(Integer rid, Module pf) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Integer> findFidByRid(Role r) {
		String hql ="select rf.function.id from RoleFunction  rf where rf.role.id=?";
		List fids =super.getHibernateTemplate().find(hql,r.getId());
		return fids;
	}

	@SuppressWarnings("unchecked")
	public List<Module> findModuleHad(Integer i) {
		String hql = "select distinct rf.function.module " +
				"from RoleFunction rf where rf.role.id=?";
		
		return super.getHibernateTemplate().find(hql,i);
	
	}

	public void save(RoleFunction entity) {
		super.getHibernateTemplate().save(entity);

	}

}
